package com.zhuiyun.educations.api.teacher.mapper;

import com.zhuiyun.educations.api.teacher.entity.Teacher;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.BaseMapper;

import java.util.List;

/**
 * @ClassName TeacherMapper
 * @Description TODO 教师信息持久层
 * @Author 杨友朋
 * @Date 2023/6/19 14:54
 **/
@Mapper
public interface TeacherMapper extends BaseMapper<Teacher> {
    /**
    * @Author 杨友朋
    * @Description TODO 全查教师信息
    * @Date 2023/6/21 20:38
    * @Return List<Teacher>
    * @param teacher
    */
    @Select("<script>select * from teacher where del_flag=0 " +
            "<if test='tName!=null and tName!=&quot;&quot;'> and t_name like concat('%',#{tName},'%')</if>" +
            "<if test='tSex!=null and tSex!=&quot;&quot;'> and t_sex=#{tSex}</if>" +
            "<if test='tEducation!=null and tEducation!=&quot;&quot;'> and t_education=#{tEducation}</if>" +
            "</script>")
    List<Teacher> selectTeacher(Teacher teacher);

    /**
    * @Author 杨友朋
    * @Description TODO 添加教师信息
    * @Date 2023/6/21 20:39
    * @Return Integer
    * @param teacher
    */    @Insert("insert into teacher (t_name,t_sex,t_education,t_seniority,t_introduction,t_honor,create_time,update_time)" +
            " values (#{tName},#{tSex},#{tEducation},#{tSeniority},#{tIntroduction},#{tHonor},#{createTime},#{updateTime})")
    Integer insertTeacher(Teacher teacher);

    /**
    * @Author 杨友朋
    * @Description TODO 根据id修改教师信息
    * @Date 2023/6/21 20:39
    * @Return Integer
    * @param teacher
    */
    @Update("<script>" +
                "update teacher set " +
                "<if test='tName!=null'>t_name=#{tName},</if>" +
                "<if test='tSex!=null'>t_sex=#{tSex},</if>" +
                "<if test='tEducation!=null'>t_education=#{tEducation},</if>" +
                "<if test='tSeniority!=null'>t_seniority=#{tSeniority},</if>" +
                "<if test='tIntroduction!=null'>t_introduction=#{tIntroduction},</if>" +
                "<if test='tHonor!=null'>t_honor=#{tHonor},</if>" +
                "<if test='createTime!=null'>create_time=#{createTime},</if>" +
                "<if test='updateTime!=null'>update_time=#{updateTime} </if>" +
                " where id=#{id}" +
            "</script>")
    Integer updateTeacher(Teacher teacher);

    /**
    * @Author 杨友朋
    * @Description TODO 根据id删除教师信息
    * @Date 2023/6/21 20:40
    * @Return Integer
    * @param id
    */
    @Update("update teacher set del_flag=1 where id=#{id}")
    Integer deleteTeacherById(Integer id);

    /**
    * @Author 杨友朋
    * @Description TODO 根据ids批量删除教师信息
    * @Date 2023/6/21 20:40
    * @Return Integer
    * @param ids
    */
    @Update("<script>" +
                "update teacher set del_flag=1 where id IN " +
                " <foreach collection='ids' item='id' open='(' separator=',' close=')'>" +
                "            #{id}" +
                "        </foreach>" +
            "</script>")
    Integer deleteTeacherByIds(@Param(value = "ids")List<Integer> ids);
}
